
/**
 * DOM 操作封装
 */
let local = require('../utils/local.js')

//1.封装获取单个节点
function getEle(selector) {
    return document.querySelector(selector)
}
//2.封装获取多个节点
function getEles(selector) {
    return document.querySelectorAll(selector)
}

//封装文档加载事件
function ready(cb) {
    window.addEventListener('DOMContentLoaded', function () {
        cb()
    })
}

function boop(obj) {
    document.body.innerHTML += `
 <div class="main"></div>
    <div class="footer mt20">
        <ul>
            <li>
                <a href="home.html" class='${obj == 'home' ? 'active' : ''}'>
                    <i class="iconfont icon-shouye"></i>
                    <p>首页</p>
                </a>
            </li>
            <li>
                <a href="sports.html" class="${obj == 'sports' ? 'active' : ''}">
                    <i class="iconfont icon-huwaiyundong">
                    </i>
                    <p>运动</p>
                </a>
            </li>
            <li>
                <a href="circle.html" class='${obj == 'circle' ? 'active' : ''}'>
                    <i class="iconfont icon-quanzi"></i>
                    <p>圈子</p>
                </a>
            </li>
            <li>
                <a href="my.html" class='${obj == 'my' ? 'active' : ''}'>
                    <i class="iconfont icon-wode"></i>
                    <p>我的</p>
                </a>
            </li>
        </ul>

    </div>
`
}





function addEvent(obj, colback, type='click') {
    getEle(obj).addEventListener(type, function () {
        colback()
    })
}


function isLogin() {
    let token = local.get('tk');

    if (!token) {
        location.href = 'login.html'
    }
}




//暴露出去
module.exports = {
    getEle,
    getEles,
    ready,
    addEvent,
    boop,
    isLogin
}
